CHOWN

Section: System Calls (2)
Index Return to Main Contents

BSD mandoc
BSD 4  

NAME

chown fchown - change owner and group of a file  

SYNOPSIS

Fd #include <sys/types.h> Fd #include <unistd.h> Ft int Fn chown const char *path uid_t owner gid_t group Ft int Fn fchown int fd uid_t owner uid_t group  

DESCRIPTION

The owner ID and group ID of the file named by Fa path or referenced by Fa fd is changed as specified by the arguments Fa owner and Fa group . The owner of a file may change the Fa group to a group of which he or she is a member, but the change Fa owner capability is restricted to the super-user.

Fn Chown clears the set-user-id and set-group-id bits on the file to prevent accidental or mischievous creation of set-user-id and set-group-id programs.

Fn Fchown is particularly useful when used in conjunction with the file locking primitives (see flock(2)).

One of the owner or group id's may be left unchanged by specifying it as -1.  

RETURN VALUES

Zero is returned if the operation was successful; -1 is returned if an error occurs, with a more specific error code being placed in the global variable errno  

ERRORS

Fn Chown will fail and the file will be unchanged if:

Bq Er ENOTDIR
A component of the path prefix is not a directory.
Bq Er ENAMETOOLONG
A component of a pathname exceeded {NAME_MAX} characters, or an entire path name exceeded {PATH_MAX} characters.
Bq Er ENOENT
The named file does not exist.
Bq Er EACCES
Search permission is denied for a component of the path prefix.
Bq Er ELOOP
Too many symbolic links were encountered in translating the pathname.
Bq Er EPERM
The effective user ID is not the super-user.
Bq Er EROFS
The named file resides on a read-only file system.
Bq Er EFAULT
Fa Path points outside the process's allocated address space.
Bq Er EIO
An I/O error occurred while reading from or writing to the file system.

Fn Fchown will fail if:

Bq Er EBADF
Fa Fd does not refer to a valid descriptor.
Bq Er EINVAL
Fa Fd refers to a socket, not a file.
Bq Er EPERM
The effective user ID is not the super-user.
Bq Er EROFS
The named file resides on a read-only file system.
Bq Er EIO
An I/O error occurred while reading from or writing to the file system.

 

SEE ALSO

chown(8), chgrp(1), chmod(2), flock(2)  

STANDARDS

The Fn chown function is expected to conform to St -p1003.1-88 .  

HISTORY

The Fn fchown function call appeared in BSD 4.2

The Fn chown and Fn fchown functions were changed to follow symbolic links in BSD 4.4


 

Index

NAME
SYNOPSIS
DESCRIPTION
RETURN VALUES
ERRORS
SEE ALSO
STANDARDS
HISTORY

This document was created by man2html, using the manual pages.
Time: 16:29:00 GMT, April 18, 2022